home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / inetray / rpc.inetrayd.c < prev    next >
C/C++ Source or Header  |  1993-08-19  |  16KB  |  654 lines

  1. /*======================================================================
  2.                     R P C . I N E T R A Y D . C 
  3.                     doc: Mon Feb 24 16:24:35 1992
  4.                     dlm: Thu Aug 19 23:08:22 1993
  5.                     (c) 1992 ant@julia
  6.                     uE-Info: 430 24 T 0 0 72 10 2 8 ofnI
  7. ======================================================================*/
  8.  
  9. /*#define        VERBOSE         /* babble */
  10. /*#define        TRACEWORKERS        /* trace worker pids */
  11.  
  12. #include    <string.h>        /* The long and sad inclusion story */
  13. #include    <signal.h>
  14. #include    <netdb.h>    /* Prefer system over rpc/netdb.h */
  15. #include    <stdio.h>
  16. #include    <pwd.h>
  17. #include    <errno.h>
  18. #include    <syslog.h>
  19. #include    <sys/file.h>        /* A/UX wants that */
  20. #include    <sys/types.h>
  21. #include    <sys/socket.h>
  22. #include    <sys/param.h>
  23. #include    <sys/wait.h>
  24. #ifndef INADDR_ANY
  25. #include    <netinet/in.h>
  26. #endif
  27. #include    <rpc/rpc.h>
  28. #include    "rayshade.h"
  29. #include    "picture.h"
  30. #include    "version.h"
  31. #include    "patchlevel.h"
  32. #include    "inetray.h"
  33. #include    "config.h"
  34. #include     "common.h"
  35. #include    "irtrace.h"
  36. #include    "utils.h"
  37. #include    "lbuffer.h"
  38. #include    "stderr.h"
  39.  
  40. #define MAXARGS    256            /* max # of args allowed */
  41. #define ARGBUFSZE 8192            /* max buffer for args */
  42.  
  43. extern int    errno;            /* for connection retry */
  44. extern void     inetray_1();        /* generated dispatch routine */
  45.  
  46. EXPORT int     _rpcpmstart;        /* Started by a port monitor ? */
  47.  
  48. static int     argc;            /* argcount */
  49. static char     *argv[MAXARGS];        /* argvector */
  50. static char     argbuf[ARGBUFSZE];    /* buffer for argv */
  51. static int    pid = -1;        /* pid of child */
  52. static int    bufPid = -1;        /* pid of lBuffer */
  53. static char    rName[MAXHOSTNAMELEN];    /* remote hostname */
  54. static int    lSize;            /* size of scanline */
  55. static int    sock = -1;        /* result socket */
  56. static XDR    xdrs;            /* result XDR stream */
  57. static int    key;            /* session key */
  58. static u_long     progNum;        /* program number (INETRAY + wid) */
  59. static uid_t    uid;            /* user id (ideal) */
  60. static int    bufPipe[2];        /* pipe from live buffer */
  61. static char    initialized = FALSE;    /* files read */
  62. static int    firstFrame;        /* deferred startframe number */
  63. static char    bufReadingSock = FALSE;    /* live buffer is reading socket */
  64. static int    rpcSock,proto;        /* socket & proto to register */
  65. static SVCXPRT    *transport;        /* transport handle */
  66. static int    bNr = -1;        /* bNr of last request */
  67.  
  68. /*----------------------------------------------------------------------*/
  69.  
  70. static void parseQuote(s,spp,bpp)        /* parse quoted arg */
  71. char s[]; int *spp,*bpp;
  72. {
  73.     argv[argc] = &argbuf[*bpp];
  74.     (*spp)++;
  75.     while (s[*spp] != '\'')    {    /* copy simply */
  76.         argbuf[(*bpp)++] = s[(*spp)++];
  77.     }
  78.     argbuf[(*bpp)++] = '\0';
  79.     (*spp)++;                /* skip quote char */
  80. }
  81.  
  82. static void parseArgs(s)            /* break up s into argv */
  83. char s[];
  84. {
  85.     int bufp,sp,sl;
  86.  
  87.     argc = bufp = sp = 0;
  88.     sl = strlen(s);
  89.     while (sp < sl) {
  90.         if (s[sp] != '\'') {
  91.             sp++;
  92.             continue;
  93.         }
  94.         parseQuote(s,&sp,&bufp);
  95.         argc++;
  96.     }
  97.     argv[argc] = NULL;
  98. }
  99.  
  100. static void exitClean(s)            /* kill & exit */
  101. int s;
  102. {
  103. #ifdef VERBOSE
  104.     SYSLOG(LOG_NOTICE,"exitClean(%d)",s);
  105. #endif
  106.     if (pid > 0) kill(pid,SIGKILL);
  107.     if (!_rpcpmstart)
  108.          (void)pmap_unset(progNum,IRV1);
  109.     CLOSELOG();
  110.     closeStderr();
  111.     exit(s);
  112. }
  113.     
  114. /*----------------------------------------------------------------------*/
  115.  
  116. static void checkAbort()            /* abort on crash */
  117. {
  118.     fd_set    selRead;
  119.     int    status;
  120.  
  121.     signal(SIGALRM,checkAbort);        /* sysV yummy dummy */
  122.  
  123. #ifdef VERBOSE
  124.     SYSLOG(LOG_NOTICE,"Checking for abort");
  125. #endif
  126.     if (pid > 0) {                /* check child exit stat */
  127. #ifdef VERBOSE
  128.         SYSLOG(LOG_NOTICE,"Checking for child termination");
  129. #endif
  130.         if (waitpid(pid,&status,WNOHANG) > 0) {
  131.             pid = 0;
  132.             if (status != 0) {
  133.                 SYSLOG(LOG_ERR,"Abort: worker exit status %d",status);
  134.                 exitClean(1);
  135.             }
  136.         }
  137.     }
  138.  
  139.     if (sock == -1) {            /* not yet set up */
  140.         SYSLOG(LOG_ERR,"Lost INIT request");
  141.         exitClean(1);
  142.     }
  143.     
  144. #ifdef VERBOSE
  145.     SYSLOG(LOG_NOTICE,"Checking socket");
  146. #endif
  147.     
  148.     if (bufReadingSock) {            /* watch out! */
  149.         FD_ZERO(&selRead);
  150.         FD_SET(bufPipe[IN],&selRead);    /* check buffer pipe */
  151.         if (select(bufPipe[IN]+1,&selRead,NULL,NULL,&now) < 0) {
  152.             SYSLOG(LOG_ERR,"select(): %m");
  153.             exitClean(1);
  154.         }
  155.         bufReadingSock = !FD_ISSET(bufPipe[IN],&selRead);
  156.     }
  157.  
  158.     if (bufReadingSock) return;        /* really reading -> wait */
  159.         
  160.     FD_ZERO(&selRead);            /* check connection */
  161.     FD_SET(sock,&selRead);
  162.     if (select(sock+1,&selRead,NULL,NULL,&now) < 0) {
  163.         SYSLOG(LOG_ERR,"select(): %m");
  164.         exitClean(1);
  165.     }
  166.     if (FD_ISSET(sock,&selRead)) {        /* read() would return 0 */
  167.         SYSLOG(LOG_ERR,"Dispatcher disappeared");
  168.         exitClean(1);
  169.     }
  170. }
  171.  
  172. static void setupTimer()
  173. {
  174.     struct itimerval chkClntT;
  175.     
  176. #ifdef VERBOSE
  177.     SYSLOG(LOG_NOTICE,"setupTimer()");
  178. #endif
  179.     chkClntT.it_interval.tv_sec = chkClntT.it_value.tv_sec = CHKCLNT;
  180.     chkClntT.it_interval.tv_usec = chkClntT.it_value.tv_usec = 0;
  181.     signal(SIGALRM,checkAbort);
  182.     if (setitimer(ITIMER_REAL,&chkClntT,NULL) < 0) {
  183.         SYSLOG(LOG_ERR,"setitimer: %m");
  184.         exitClean(1);
  185.     }
  186. }
  187.  
  188. static void registerSelf()        /* register self */
  189. {
  190.     transport = svcudp_create(rpcSock);
  191.     if (transport == NULL) {
  192.         SYSLOG(LOG_ERR,"cannot create udp service.");
  193.         exitClean(1);
  194.     }
  195.     if (!svc_register(transport,progNum,IRV1,inetray_1,proto)) {
  196.         SYSLOG(LOG_ERR,"unable to register (%d,VER,udp)",progNum);
  197.         exitClean(1);
  198.     }
  199. #ifdef VERBOSE
  200.     SYSLOG(LOG_NOTICE,"Opening Stderr");
  201. #endif
  202.     if (openStderr("rpc.inetrayd") < 0) exitClean(1);
  203. }
  204.  
  205. static void slaveSvcs(n)        /* start secondary servers */
  206. int n;                    /* clean up & register */
  207. {
  208.     int    pid,thisProg;
  209.  
  210.     thisProg = progNum;
  211.     while (n-- > 0) {        /* start n */
  212.         thisProg++;
  213.         pid = fork();
  214.         if (pid < 0) {
  215.             SYSLOG(LOG_ERR,"fork: %m");
  216.             exitClean(1);
  217.         }
  218.         if (pid == 0) {        /* new server */
  219.             progNum = thisProg;
  220.             svc_destroy(transport);
  221.             (void)pmap_unset(progNum,IRV1);
  222.             _rpcpmstart = FALSE;
  223.             rpcSock = RPC_ANYSOCK;
  224.             proto = IPPROTO_UDP;
  225.             registerSelf();
  226.             setupTimer();
  227. #ifdef VERBOSE
  228.             SYSLOG(LOG_NOTICE,"INIT: forked prog # %d",progNum);
  229. #endif
  230.             return;
  231.         }
  232.     }
  233. }
  234.  
  235. /*----------------------------------------------------------------------*/
  236.  
  237. static void killSelf()            /* received SIGINT(kill) signal */
  238. {
  239.     if (!xdrrec_endofrecord(&xdrs,TRUE)) {
  240.         SYSLOG(LOG_ERR,"xdrrec_endofrecord() failed");
  241.         exitClean(1);
  242.     } 
  243.     exit(0);
  244. }
  245.  
  246. /*----------------------------------------------------------------------*/
  247.  
  248. static writeit(dummy,buf,nbyte)            /* XDR write routine */
  249. char *dummy,*buf; int nbyte;
  250. {
  251.     int writ;
  252.  
  253.     writ = write(sock,buf,nbyte);
  254.     if (writ < 0) SYSLOG(LOG_ERR,"XDR write: %m");
  255.     return writ;
  256. }
  257.  
  258. static void sendResult(bNr,bSz,block,skip)    /* send whole resultblock back */
  259. int bNr,bSz; Scanline *block; int skip;
  260. {
  261.     pixArr    res;
  262.     int    i;
  263.     
  264.     bNr += skip;
  265.     if (!xdr_int(&xdrs,&bNr)) {
  266.         SYSLOG(LOG_ERR,"xdr_int() failed");
  267.         exitClean(1);
  268.     }
  269.     
  270.     res.pixArr_len = lSize;
  271.     for (i=skip*bSz+1; i<=(skip+1)*bSz; i++) {
  272.         res.pixArr_val = (xdrPix *)block[i].pix;
  273.         if (!xdr_pixArr(&xdrs,&res)) {
  274.             SYSLOG(LOG_ERR,"xdr_pixArr() failed");
  275.             exitClean(1);
  276.         }
  277.     }
  278.     if (!xdrrec_endofrecord(&xdrs,TRUE)) {
  279.         SYSLOG(LOG_ERR,"xdrrec_endofrecord() failed");
  280.         exitClean(1);
  281.     }
  282. }
  283.  
  284. /*----------------------------------------------------------------------*/
  285.  
  286. void *init_1(param)                /* init self */
  287. iPrm *param;
  288. {
  289.     int    wid,wpid;
  290.     char    wd[MAXPATHLEN],v[8],*cp,*getcwd();
  291.     struct passwd        *p;
  292.     struct hostent        *host;
  293.     struct sockaddr_in    name;
  294.     
  295. #ifdef VERBOSE
  296.     SYSLOG(LOG_NOTICE,"INIT:");
  297. #endif
  298.     if (pid != -1)                /* only once */
  299.         return (void *)NULL;        
  300.  
  301.     pid = 0;                /* initialized */
  302.     slaveSvcs(param->nSvcs-1);        /* start 2nd svcs */
  303.     
  304.     signal(SIGINT,SIG_IGN);            /* ignore kill signal */
  305.  
  306.     strncpy(rName,param->rName,MAXHOSTNAMELEN);
  307.     key = param->key;            /* session key */
  308.  
  309.     if (uid == 0) {                /* set default uid */
  310.         if (setuid(param->uid) < 0) {
  311.             SYSLOG(LOG_NOTICE,"setuid: %m");
  312.         }
  313.         uid = geteuid();        /* get effective uid */
  314.         if (uid == 0) {
  315.             SYSLOG(LOG_ERR,"can't run as root");
  316.             exitClean(1);
  317.         }
  318.     }
  319.     p = getpwuid(uid);            /* get user info */
  320.     if (p == NULL) {
  321.         SYSLOG(LOG_ERR,"illegal user id %d",uid);
  322.         exitClean(1);
  323.     }
  324.     
  325.     addHome(uid,param->cwd,wd);        /* get right dir */
  326.     if (chdir(wd) < 0) {            /* try to get there */
  327.         SYSLOG(LOG_NOTICE,"WARNING: chdir(%s): %m",wd);
  328.     }
  329.  
  330.     if (key != 0) {                /* only pinged */
  331.         parseArgs(param->cmdLine);
  332.     }
  333.                         /* init socket */
  334.     if ((host = gethostbyname(rName)) == NULL) {
  335.         SYSLOG(LOG_ERR,"gethostbyname(%s) failed!",rName);
  336.         exitClean(1);
  337.     }
  338.     name.sin_family = AF_INET;
  339.     name.sin_port = htons(param->rPort);
  340.     memcpy((char *)&name.sin_addr,host->h_addr_list[0],host->h_length);
  341.  
  342.     if ((sock = socket(PF_INET,SOCK_STREAM,0)) < 0) {
  343.         SYSLOG(LOG_ERR,"socket: %m");
  344.         exitClean(1);
  345.     }
  346.     if (connect(sock,&name,sizeof(name)) < 0) {
  347.         if (errno == ECONNREFUSED) {    /* retry once */
  348.             close(sock);
  349.             sleep((rand()%2)+1);    /* wait random time */
  350.                 if ((sock = socket(PF_INET,SOCK_STREAM,0)) < 0) {
  351.                         SYSLOG(LOG_ERR,"socket: %m");
  352.                         exitClean(1);
  353.                 }
  354.             if (connect(sock,&name,sizeof(name)) < 0) {
  355.                         SYSLOG(LOG_ERR,"connect: %m");
  356.                 exitClean(1);
  357.             }
  358.         } else {
  359.                     SYSLOG(LOG_ERR,"connect: %m");
  360.             exitClean(1);
  361.         }
  362.     }
  363.  
  364.     xdrrec_create(&xdrs,0,0,NULL,NULL,writeit); /* create XDR */
  365.     xdrs.x_op = XDR_ENCODE;
  366.     wid = progNum - INETRAY;        /* send back info */
  367.     if (!xdr_int(&xdrs,&wid)) {        /* worker id */
  368.         SYSLOG(LOG_ERR,"xdr_int() failed");
  369.         exitClean(1);
  370.     }
  371.     wpid = getpid();
  372.     if (!xdr_int(&xdrs,&wpid)) {        /* pid */
  373.         SYSLOG(LOG_ERR,"xdr_int() failed");
  374.         exitClean(1);
  375.     }
  376.     cp = p->pw_name;            /* user name */
  377.     if (!xdr_string(&xdrs,&cp,32)) {
  378.         SYSLOG(LOG_ERR,"xdr_string() failed");
  379.         exitClean(1);
  380.     }
  381.     getcwd(wd,MAXPATHLEN);            /* working dir */
  382.     stripHead(STRIPHEAD,wd);
  383.     stripHome(uid,wd); 
  384.     cp = wd;
  385.     if (!xdr_string(&xdrs,&cp,MAXPATHLEN)) {
  386.         SYSLOG(LOG_ERR,"xdr_string() failed");
  387.         exitClean(1);
  388.     }
  389.     sprintf(v,"%s%d",VERSION,PATCHLEVEL);    /* version check */
  390.     cp = v;
  391.     if (!xdr_string(&xdrs,&cp,8)) {
  392.         SYSLOG(LOG_ERR,"xdr_string() failed");
  393.         exitClean(1);
  394.     }
  395.     
  396.     if (!xdrrec_endofrecord(&xdrs,TRUE)) {
  397.         SYSLOG(LOG_ERR,"xdrrec_endofrecord() failed");
  398.         exitClean(1);
  399.     }
  400.  
  401.     if (param->sendIn) {            /* receive file */
  402.         if (pipe(bufPipe) < 0) {
  403.             SYSLOG(LOG_ERR,"pipe: %m");
  404.             exitClean(1);
  405.         }
  406.         bufReadingSock = TRUE;        /* buffer is reading */
  407.         bufPid = lPostBuffer(sock,bufPipe);
  408.     }
  409.  
  410. #ifdef VERBOSE
  411.     SYSLOG(LOG_NOTICE,"INIT done");
  412. #endif
  413.     return (void *)NULL;            /* dont reply rpc */
  414. }
  415.  
  416. int *wait_1(keyP)                /* wait 4 worker 2 die */
  417. int *keyP;
  418. {
  419.     int    status,dPid;
  420.     static int res = 0;
  421.     
  422. #ifdef VERBOSE
  423.     SYSLOG(LOG_NOTICE,"WAITING FOR: %d",pid);
  424. #endif
  425.     if (pid < 0) exit(0);            /* not initialized */
  426.     if (*keyP != key) {             /* authorize */
  427.         return (int *)NULL;
  428.     }
  429.     if (pid > 0) {                /* one has been started */
  430.         reStartWait:
  431.         if ((dPid = waitpid(pid,&status,0)) < 0) { /* wait for it */
  432.             if (errno == EINTR) goto reStartWait;
  433.             SYSLOG(LOG_ERR,"wait: %m");
  434.             exitClean(1);
  435.         }
  436.         if (status != 0) {
  437.             SYSLOG(LOG_NOTICE,"worker exit status %d",status);
  438.         }
  439.         if (dPid != pid) {        /* what happened ? */
  440.             kill(pid,SIGKILL);    /* abort ! */
  441.             SYSLOG(LOG_ERR,"pid of dead %d instead of %d",dPid,pid);
  442.             exitClean(1);
  443.         }
  444. #ifdef VERBOSE
  445.         SYSLOG(LOG_NOTICE,"pid %d returned %d",dPid,status);
  446. #endif
  447.         pid = 0;
  448.     }
  449. #ifdef VERBOSE
  450.     SYSLOG(LOG_NOTICE,"WAITING done");
  451. #endif
  452.     return &res; 
  453. }        
  454.  
  455. int *startframe_1(param)            /* start new frame */
  456. sfPrm *param;
  457. {
  458.     static int res = 0;
  459.     int    status;
  460.  
  461. #ifdef VERBOSE
  462.     SYSLOG(LOG_NOTICE,"STARTFRAME:");
  463. #endif
  464.     if (pid < 0) exit(0);            /* not initialized */
  465.     if (param->key != key) {        /* authorize */
  466.         return (int *)NULL;
  467.     }
  468.     wait_1(&(param->key));
  469.     if (initialized)            /* start new frame */
  470.         RSStartFrame(param->fNr);
  471.     else                    /* defer */
  472.         firstFrame = param->fNr;
  473.     bNr = -1;                /* clear saved block# */
  474. #ifdef VERBOSE
  475.     SYSLOG(LOG_NOTICE,"STARTFRAME done");
  476. #endif
  477.     return &res;
  478. }
  479.  
  480. void *traceblock_1(param)            /* trace block of lines */
  481. tbPrm *param;
  482. {
  483.     int    pgrp,status,saveIn,i;
  484.     Scanline *resBlock,*Raytrace();
  485.  
  486. #ifdef VERBOSE
  487.     SYSLOG(LOG_NOTICE,"TRACEBLOCK msg received");
  488. #endif
  489.     if (pid < 0) exit(0);            /* not initialized */
  490.     if (param->key != key)             /* authorize */
  491.         return (void *)NULL;
  492.     if (bNr == param->bNr)            /* message resent */
  493.         return (void *)NULL;
  494. #ifdef VERBOSE
  495.     SYSLOG(LOG_NOTICE,"TRACEBLOCK started");
  496. #endif
  497.  
  498.     bNr = param->bNr;            /* avoid doublework */
  499.     
  500.     if (!initialized) {            /* deferred stuff */
  501. #ifdef VERBOSE
  502.         SYSLOG(LOG_NOTICE,"initializing");
  503. #endif
  504.         if (bufPid > 0) {        /* buffered stdin */
  505.             saveIn = dup(IN);
  506.             close(IN);
  507.             dup(bufPipe[IN]);
  508.             close(bufPipe[IN]);
  509.         }
  510.         lSize = RaytraceInit(argc,argv);
  511.         if (bufPid > 0) {        /* restore stdin */
  512.             waitpid(bufPid,NULL,0);
  513.             bufPid = -1;
  514.             bufReadingSock = FALSE;
  515.             close(IN);
  516.             dup(saveIn);
  517.         }
  518.         RSStartFrame(firstFrame);
  519.         initialized = TRUE;
  520. /*        wait(NULL);            /* get status */
  521.     }
  522.     wait_1(&(param->key));
  523.     pid = fork();                /* make new */
  524.     if (pid < 0) {
  525.         SYSLOG(LOG_ERR,"fork: %m");
  526.         exitClean(1);
  527.     }
  528.     if (pid == 0) {                /* child */
  529.         nice(NICEDAEMON);        /* run nicely */
  530.  
  531.         signal(SIGINT,killSelf);
  532.         resBlock = Raytrace(param->nBlocks*param->bSz,
  533.                     param->lNr);
  534.         signal(SIGINT,SIG_IGN);
  535.         for (i=0; i<param->nBlocks; i++)
  536.             sendResult(param->bNr,
  537.                    param->bSz,
  538.                    resBlock,i);
  539. #ifdef VERBOSE
  540.         SYSLOG(LOG_NOTICE,"> EXIT");
  541. #endif
  542.         exit(0);
  543.     }
  544. #ifdef TRACEWORKERS
  545.     SYSLOG(LOG_NOTICE,"pid %d forked",pid);
  546. #endif
  547. #ifdef VERBOSE
  548.     SYSLOG(LOG_NOTICE,"pid %d forked",pid);
  549. #endif
  550.     return NULL;                /* don't block */
  551. }
  552.  
  553. int *kill_1(keyP)                /* kill worker */
  554. int *keyP;
  555. {
  556.     static int res = 0;
  557.     
  558. #ifdef VERBOSE
  559.     SYSLOG(LOG_NOTICE,"KILLING: %d",pid);
  560. #endif
  561.     if (pid < 0) exit(0);            /* not initialized */
  562.     if (*keyP != key) {            /* authorize */
  563.         return (int *)NULL;
  564.     }
  565.     if (pid > 0) (void)kill(pid,SIGINT);
  566.     return &res;
  567. }
  568.  
  569. void *terminate_1(keyP)                /* terminate */
  570. int *keyP;
  571. {
  572. #ifdef VERBOSE
  573.     SYSLOG(LOG_NOTICE,"TERMINATE:");
  574. #endif
  575.     if (pid < 0) exit(0);            /* not initialized */
  576.     if (*keyP != key) {            /* authorize */
  577.         return;
  578.     }
  579.     if (pid > 0) {                /* force */
  580.         kill(pid,SIGKILL);
  581.         wait_1(keyP);
  582.     }
  583.     if (bufPid > 0)
  584.         kill(bufPid,SIGKILL);
  585. #ifdef VERBOSE
  586.     SYSLOG(LOG_NOTICE,"TERMINATE done");
  587. #endif
  588. /*    if (progNum == INETRAY)            /* wid == 0 */
  589. /*        CLOSELOG();*/
  590.     exitClean(0);
  591. }
  592.  
  593. /*======================================================================*/
  594.  
  595. int _rpcfdtype = SOCK_DGRAM;    /* Whether Stream or Datagram ? */
  596.  
  597. main(ac,av)
  598. int ac; char *av[];
  599. {
  600.     struct sockaddr_in     saddr;
  601.     int asize = sizeof(saddr);
  602.     int ssize = sizeof(int);
  603.     int     fd;
  604.  
  605.     _rpcpmstart = (ac == 1);            /* logging */
  606.     if (!_rpcpmstart) CLOSELOG();
  607.     OPENLOG("rpc.inetrayd");
  608. #ifdef VERBOSE
  609.     SYSLOG(LOG_NOTICE,"started!");
  610. #endif
  611.     setupTimer();
  612.  
  613. #ifdef VERBOSE
  614.     SYSLOG(LOG_NOTICE,"Timer set up");
  615. #endif
  616.     if (_rpcpmstart) {                /* inetd */
  617.         rpcSock = 0;
  618.         proto = 0;
  619.         if (getsockname(rpcSock, (struct sockaddr *)&saddr, &asize) < 0) {
  620.             SYSLOG(LOG_ERR,"socket: %m");
  621.             exitClean(1);
  622.         }
  623.         if (saddr.sin_family != AF_INET) {
  624.             SYSLOG(LOG_ERR,"illegal protocol");
  625.             exitClean(1);
  626.         }
  627.         if (getsockopt(0, SOL_SOCKET, SO_TYPE,
  628.                 (char *)&_rpcfdtype, &ssize) == -1) {
  629.             SYSLOG(LOG_ERR,"getsockopt: %m");
  630.             exitClean(1);
  631.         }
  632.     } else {                /* inetray.starter */
  633.         (void)pmap_unset(INETRAY,IRV1);
  634.         rpcSock = RPC_ANYSOCK;
  635.         proto = IPPROTO_UDP;
  636.     }
  637.  
  638. #ifdef VERBOSE
  639.     SYSLOG(LOG_NOTICE,"trying to register self...");
  640. #endif
  641.     uid = geteuid();            /* set up */
  642.     progNum = INETRAY;
  643.     registerSelf();
  644.  
  645. #ifdef VERBOSE
  646.     SYSLOG(LOG_NOTICE,"waiting for request...");
  647. #endif
  648.     svc_run();
  649.     SYSLOG(LOG_ERR,"svc_run returned");
  650.     exitClean(1);
  651.     /* NOTREACHED */
  652. }
  653.  
  654.